<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      body {
        height: 100vh;
        display: flex;
        justify-content: center;
      }
      #app {
        overflow: hidden;
        margin: auto;
        width: 30%;
        height: 600px;
        background-color: #eee;
        display: flex;
        flex-direction: column;
        align-items: center;
        overflow-y: scroll;
      }
      img {
        margin-bottom: 8px;
      }
    </style>
  </head>
  <body>
    <div id="app"></div>

    <script>
      // 模拟数据
      const imgUrls = new Array(1000).fill(
        `https://c-ssl.duitang.com/uploads/blog/202109/24/20210924081215_63853.jpeg?`
      );

      const root = document.getElementById("app");
      let o = 0;
      root.addEventListener("scroll", (e) => {
        if (e.target.scrollTop > o * 100 + 8 * o - 10 * 100) {
          createElement();
        }
      });
      function createElement() {
        const fragment = document.createDocumentFragment();
        for (let i = 0; i < 10; i++) {
          const img = document.createElement("img");
          img.setAttribute("width", 100);
          img.setAttribute("height", 100);
          img.setAttribute("src", imgUrls[o] + o);
          fragment.appendChild(img);
          o++;
        }
        root.appendChild(fragment);
      }
      createElement();
    </script>
  </body>
</html>
